$(function(){
  var page = 1;
  var pageSize = 5;
  render();
  function render(){
    $.ajax({
      url:'/category/queryTopCategoryPaging',
      type:'get',
      data:{
        page:page,
        pageSize:pageSize
      },
      success:function(info){
        console.log(info);
        $("tbody").html(template("tmp",info))
        $("#paginator").bootstrapPaginator({
          bootstrapMajorVersion:3,
          currentPage:page,
          totalPages:Math.ceil(info.total / info.size),
          onPageClicked:function(a,b,c,p){
            page = p;
            render();
          }
        })
      }
    })
  }

  $(".btn_add").on("click",function(){
    console.log(1);
    
    $("#addModal").modal("show");
  })


  //使用表单校验插件
$("form").bootstrapValidator({
  feedbackIcons: {
    valid: 'glyphicon glyphicon-ok',
    invalid: 'glyphicon glyphicon-remove',
    validating: 'glyphicon glyphicon-refresh'
  },

  fields: {
    //校验用户名，对应name表单的name属性
    categoryName: {
      validators: {
        //不能为空
        notEmpty: {
          message: '一级名称不能为空'
        },
      }
    },
  }

});

$("form").on('success.form.bv', function (e) {
  e.preventDefault();
  //使用ajax提交逻辑
  $.ajax({
    url:'/category/addTopCategory',
    type:'post',
    data:$("form").serialize(),
    success:function(info){
      console.log(info);
      if(info.success){
        page = 1;
        render();
    $("#addModal").modal("hide");
    $('form')
    .data('bootstrapValidator')
    .resetForm(true)
      }
     
    }
  })
});



})